<template>

  <el-form :model="loginFrom"
           class="login-container">
    <h3>系统登录</h3>
    <el-form-item>
      <el-input type="input"
                v-model="loginFrom.userName"
                placeholder="请输入账号"></el-input>
    </el-form-item>
    <el-form-item>
      <el-input type="passWord"
                v-model="loginFrom.passWord"
                placeholder="请输入密码"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary"
                 @click="lgoin"> 登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { defineComponent, getCurrentInstance, onMounted, reactive, ref } from "vue";
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
export default {
  setup () {
    const { proxy } = getCurrentInstance();
    const store = useStore(); //引用 store做跨页面传值
    const router = useRouter(); //router跳转
    const loginFrom = reactive({
      userName: 'admin',
      passWord: 'admin',
    });

    const lgoin = async () => {
      let res = await proxy.$api.getMenu(loginFrom);
      store.commit('setMenu', res.menu)
      store.commit('addMenu', router)
      store.commit('setToken', res.token)
      //跳转至home页面
      router.push({ name: "home" });
    };
    return {
      loginFrom,
      lgoin,
    };
  }
}
</script>

<style lang="less" scoped>
.login-container {
  width: 350px;
  height: 250px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  border-radius: 15px;
  padding: 35px 35px 15px 35px;
  box-shadow: 0 0 25px #cacaca;
  margin: 180px auto;
  h3 {
    text-align: center;
    margin-bottom: 20px;
    color: #505450;
  }
  /deep/.el-form-item__content {
    justify-content: center;
  }
}
</style>